package cn.com.surker.sale.service.impl;

import cn.com.surker.enums.StateEnum;
import cn.com.surker.sale.entity.SaleContract;
import cn.com.surker.sale.dao.SaleContractDao;
import cn.com.surker.sale.service.SaleContractBaseService;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 销售合同表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-06-18
 */
@Service
public class SaleContractServiceImpl extends SaleContractBaseServiceImpl {

	/**
	 * 模糊查询列表
	 *
	 * @param orgId
	 * @param searchVal
	 * @param quality
	 * @param workStatus
	 * @param workNature
	 * @param contractCategory
	 * @return
	 */
	public List<SaleContract> queryVagueList(Long orgId, String searchVal, Integer quality, Integer workStatus, Integer workNature, Integer contractCategory) {
		QueryWrapper<SaleContract> qw = new QueryWrapper<>();
		if (orgId != null) {
			qw.eq("a.org_id", orgId);
		}
		if (quality != null) {
			qw.like("a.quality", quality);
		}
		if (workStatus != null) {
			qw.eq("a.work_status", workStatus);
		}
		if (workNature != null) {
			qw.eq("a.work_nature", workNature);
		}
		if (contractCategory != null) {
			qw.eq("a.contract_category", contractCategory);
		}
		if (StringUtils.isNotBlank(searchVal)) {
			//	模糊查询
			qw.and(e -> {
				e.like("a.name", searchVal).or().like("a.code", searchVal);
			});
		}

		qw.eq("a.status", StateEnum.ENABLED.getCode());
		List<SaleContract> contractList = saleContractDao.selectListV1(qw);
		return contractList;
	}

}